<template>
  <div id="dconsumeData-List">
    <el-form :model="formInline" ref="formInline" class="formInline" :inline="true" size="nini">
      <el-form-item label="消费时间" class="verify-time">
        <el-row>
          <el-col :span="11" class="time-width">
            <el-date-picker
              v-model="formInline.startTime"
              type="datetime"
              placeholder="选择开始日期"
              default-time="00:00:00">
            </el-date-picker>
          </el-col>
          <el-col :span="1" class="time-span">~</el-col>
          <el-col :span="11" class="time-width">
            <el-date-picker
              v-model="formInline.endTime"
              type="datetime"
              placeholder="选择结束日期"
              default-time="23:59:59">
            </el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="消费类型">
        <el-select clearable v-model="formInline.type" filterable placeholder="选择消费类型">
          <!--<el-option label="所有景区" value=""></el-option>-->
          <el-option v-for="(item,index) in typeList"
                     :key="item.id"
                     :label="item.name"
                     :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-button type="primary" size="small"  @click="search()">搜索</el-button>
      <el-button type="primary" size="small"  @click="downloadFile()">下载</el-button>
    </el-form>

    <el-table
      class="style-a"
      :data="tableData"
      size="small"
      border
      style="width:100%"
      v-loading.body="loading" element-loading-text="Loading">
      <el-table-column
        label="代理商ID"
        align="center"
        prop="orgId"
        min-width="80">
      </el-table-column>
      <el-table-column
        label="代理商名称"
        align="center"
        prop="name"
        min-width="130">
      </el-table-column>
      <el-table-column
        label="消费类型"
        align="center"
        prop="typeStr"
        min-width="75">
      </el-table-column>
      <el-table-column
        label="消费金额（元）"
        align="center"
        prop="moneyStr"
        min-width="90">
      </el-table-column>
      <el-table-column
        label="佣金（元）"
        align="center"
        prop="commissionStr"
        min-width="90">
      </el-table-column>
      <el-table-column
        label="余额（元）"
        prop="balanceStr"
        align="center"
        min-width="90">
      </el-table-column>
      <el-table-column
        label="消费时间"
        prop="cTStr"
        align="center"
        min-width="120">
      </el-table-column>
      <el-table-column
        label="内容"
        align="center"
        min-width="180">
        <template slot-scope="scope" class="handle">
          <div>
            <p class="p-content">{{scope.row.content}}</p>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[20]"
      :page-size="20"
      layout="total, prev, pager, next, jumper"
      :total="totalSize">
    </el-pagination>
  </div>
</template>
<script>
  import { getRecordList, getTypeList } from '@/api/consumeDataRecord'
  //  import ElDialog from '../../../node_modules/element-ui/packages/dialog/src/component.vue'
  export default {
//    components: {
//      ElDialog
//    },
    data() {
      return {
        loading: false,
        formInline: {
          type: null,
          startTime: null,
          endTime: null
        },
        currentPage: 1,
        totalSize: null,
        typeList: [],
        tableData: []
      }
    },
    created() {
      this.getCosumeTypeList()
      this.getConsumeList()
    },
    methods: {
      downloadFile() {
        let formInline = this.formInline
        let params = {
          type: formInline.type,
          startTime: formInline.startTime || '',
          endTime: formInline.endTime || ''
        }
        let url = process.env.BASE_API + '/distributor/consume/record/excel?param=' + JSON.stringify(params)
        window.location.href = encodeURI(url)
      },
      getCosumeTypeList() {
        getTypeList().then(res => {
          let data = res.data
          if (data.errorCode === 'E_000') {
            this.typeList = data.body
          }
        })
      },
      search() {
        this.currentPage = 1
        this.getConsumeList()
      },
      handleCurrentChange(val) {
        this.currentPage = val
        this.getConsumeList()
      },
      getConsumeList() {
        let params = {
          pageNumber: this.currentPage,
          pageSize: 20,
          startTime: new Date(this.formInline.startTime).getTime() || null,
          endTime: new Date(this.formInline.endTime).getTime() || null,
          type: this.formInline.type
        }
        this.loading = true
        getRecordList(params).then(res => {
          let data = res.data
          this.loading = false
          if (data.errorCode === 'E_000') {
            this.tableData = data.body.list
            this.totalSize = data.body.total
          }
        }).catch(() => {
          this.loading = false
        })
      }
    }
  }
</script>
<style rel="stylesheet/scss" lang="scss">
  #dconsumeData-List{
    .p-content{
      text-align: left;
    }
    .verify-time{
      .el-form-item__content{
        width: 480px;
      }
      .time-width{
        width: 220px;
      }
      .time-span{
        text-align: center;
      }
    }
    .el-dialog{
      .imgList{
        width:100%;
        img{
          width:32.9%;
          height:280px;
          padding:0 5px;
          display:inline-block;
        }
      }
    }

  }
</style>
